package com.ruoyi.electricity.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.electricity.domain.ElectricityMeterData;
import com.ruoyi.electricity.domain.TRiskWarnings;
import com.ruoyi.electricity.domain.vo.GisEquipVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.electricity.mapper.ElectricityDataMapper;
import com.ruoyi.electricity.domain.ElectricityData;
import com.ruoyi.electricity.service.ElectricityDataService;

/**
 * 用电Service业务层处理
 *
 * @author ljw
 * @date 2023-08-29
 */
@Service
public class ElectricityDataServiceImpl implements ElectricityDataService
{
    @Autowired
    private ElectricityDataMapper electricityDataMapper;


    @Override
    public void updateThresholdsForNormalAndAlarmAndWarn(ElectricityData electricityData) {
        electricityDataMapper.updateThresholdsForNormalAndAlarmAndWarn(electricityData);
    }

    /**
     * 查询用电
     *
     * @param id 用电主键
     * @return 用电
     */
    @Override
    public ElectricityData selectElectricityDataById(String id)
    {
        return electricityDataMapper.selectElectricityDataById(id);
    }

    /**
     * 查询用电列表
     *
     * @param electricityData 用电
     * @return 用电
     */
    @Override
    public List<ElectricityData> selectElectricityDataList(ElectricityData electricityData)
    {
        return electricityDataMapper.selectElectricityDataList(electricityData);
    }

    /**
     * 新增用电
     *
     * @param electricityData 用电
     * @return 结果
     */
    @Override
    public int insertElectricityData(ElectricityData electricityData)
    {
        return electricityDataMapper.insertElectricityData(electricityData);
    }

    /**
     * 修改用电
     *
     * @param electricityData 用电
     * @return 结果
     */
    @Override
    public int updateElectricityData(ElectricityData electricityData)
    {
        return electricityDataMapper.updateElectricityData(electricityData);
    }

    /**
     * 批量删除用电
     *
     * @param ids 需要删除的用电主键
     * @return 结果
     */
    @Override
    public int deleteElectricityDataByIds(String[] ids)
    {
        return electricityDataMapper.deleteElectricityDataByIds(ids);
    }

    /**
     * 删除用电信息
     *
     * @param id 用电主键
     * @return 结果
     */
    @Override
    public int deleteElectricityDataById(String id)
    {
        return electricityDataMapper.deleteElectricityDataById(id);
    }

    @Override
    public void mergeElectricityDataListToTable(List<ElectricityData> electricityDataList) {
         electricityDataMapper.mergeElectricityDataListToTable(electricityDataList);
    }

    @Override
    public void deleteElectricityDataNotInList(List<ElectricityData> list) {
        electricityDataMapper.deleteElectricityDataNotInList(list);
    }

    @Override
    public List<ElectricityData> selectElectricityDataThatNeedToSendAlarm() {
        return electricityDataMapper.selectElectricityDataThatNeedToSendAlarm();
    }

    @Override
    public void insertElectricityAlarm(List<ElectricityData> electricityDataList) {
        electricityDataMapper.insertElectricityAlarm(electricityDataList);
    }

    @Override
    public void updateElectricityAlarmStatusAsSent(ElectricityData electricityData) {
        electricityDataMapper.updateElectricityAlarmStatusAsSent(electricityData);
    }

    @Override
    public void insertElectricityDataToHistoryTable(List<ElectricityData> list) {
        electricityDataMapper.insertElectricityDataToHistoryTable(list);
    }

    @Override
    public void insertElectricityDataToDayTable(List<ElectricityData> list) {
        electricityDataMapper.insertElectricityDataToDayTable(list);
    }

    @Override
    public void deleteElectricityData() {
        electricityDataMapper.deleteElectricityData();
    }

    @Override
    public List<ElectricityData> selectElectricityHistoryDataList(ElectricityData electricityData, Date startTime, Date endTime) {
        return electricityDataMapper.selectElectricityHistoryDataList(electricityData,  startTime,  endTime);
    }

    @Override
    public List<TRiskWarnings> selectElectricityAlarmList(TRiskWarnings riskWarnings, Date startTime, Date endTime) {
        return electricityDataMapper.selectElectricityAlarmList(riskWarnings, startTime, endTime);
    }

    @Override
    public void editElectricityAlarmHandle(TRiskWarnings riskWarnings) {
        electricityDataMapper.editElectricityAlarmHandle(riskWarnings);
        if(riskWarnings.getHandleStatus().equals(1) && riskWarnings.getDeviceName() != null) {
            electricityDataMapper.updateAlarmSentFlagAsNotSent(riskWarnings.getDeviceName());
        }
    }

    @Override
    public List<GisEquipVo> selectAllGisEquips(GisEquipVo gisEquipVo) {
        return electricityDataMapper.selectAllGisEquips(gisEquipVo);
    }

    @Override
    public List<GisEquipVo> selectGisEquipsHasCoordinates() {
        return electricityDataMapper.selectGisEquipsHasCoordinates();
    }

    @Override
    public void updateGisEquipsCoordinates(GisEquipVo gisEquipVo) {
        electricityDataMapper.updateGisEquipsCoordinates(gisEquipVo);
    }

    @Override
    public void deleteElectricityDataToDayTable() {
        electricityDataMapper.deleteElectricityDataToDayTable();
    }

    @Override
    public List<ElectricityMeterData> selectElectricityDataTodayList() {
        return electricityDataMapper.selectElectricityDataTodayList();
    }
}
